#include "ModelDraw.h"

ModelDraw::ModelDraw() : m_bitmap(NULL), m_memory_dc(NULL), m_model(NULL)
{

}

ModelDraw::~ModelDraw()
{

}


bool ModelDraw::setup()
{
    m_bitmap = new wxBitmap(1024, 768);
    if( !m_bitmap ){
        goto fail;
    }

    m_memory_dc = new wxMemoryDC(*m_bitmap);
    if( !m_memory_dc ){
        goto fail;
    }

    return true;

fail:
    if( m_bitmap ){
        delete m_bitmap;
    }
    if( m_memory_dc ){
        delete m_memory_dc;
    }
    return false;
}


bool ModelDraw::teardown()
{

    return false;
}

void ModelDraw::setModel(Model* model)
{
    m_model = model;
}

void ModelDraw::drawPoint(const DL_PointData* data)
{
    if(m_memory_dc){
        m_memory_dc->SetPen(*wxRED_PEN);
        m_memory_dc->SetBrush( *wxTRANSPARENT_BRUSH );
        m_memory_dc->DrawPoint(data->x, data->y);
    }
}

void ModelDraw::drawLine(const DL_LineData* data)
{
    if(m_memory_dc){
        m_memory_dc->SetPen(*wxRED_PEN);
        m_memory_dc->SetBrush( *wxTRANSPARENT_BRUSH );
        m_memory_dc->DrawLine(data->x1,data->y1, data->x2, data->y2 );
    }
}

void ModelDraw::drawArc(const DL_ArcData* data)
{
    if(m_memory_dc){
        m_memory_dc->SetPen(*wxRED_PEN);
        m_memory_dc->SetBrush( *wxTRANSPARENT_BRUSH );
        //m_memory_dc->DrawArc()
    }


}

void ModelDraw::drawCircle(const DL_CircleData* data)
{
    if( m_memory_dc){
        m_memory_dc->SetPen(*wxRED_PEN);
        m_memory_dc->SetBrush( *wxTRANSPARENT_BRUSH );
        m_memory_dc->DrawCircle( data->cx, data->cy, data->radius );
    }
}

void ModelDraw::drawEllipse(const DL_EllipseData* data)
{

}

void ModelDraw::drawModel()
{
    if( !m_model ){
        return;
    }
    {
        std::list<DL_PointData*>::const_iterator it = m_model->m_points.begin();
        for(; it!= m_model->m_points.end(); ++it ){
            drawPoint( *it );
        }
    }
    {
        std::list<DL_LineData*>::const_iterator it = m_model->m_lines.begin();
        for(; it!= m_model->m_lines.end(); ++it ){
            drawLine( *it );
        }
    }
    {
        std::list<DL_ArcData*>::const_iterator it = m_model->m_arcs.begin();
        for(; it!= m_model->m_arcs.end(); ++it ){
            drawArc( *it );
        }
    }
    {   
        std::list<DL_CircleData*>::const_iterator it = (m_model->m_circles).begin();
        for(; it != (m_model->m_circles).end(); ++it ){
            drawCircle( *it );
        }
    }
    {
        std::list<DL_PolylineData*>::const_iterator it = m_model->m_polylines.begin();
        for(; it!= m_model->m_polylines.end(); ++it ){
            //drawPoli( *it );
        }
    }

    {
        std::list<DL_EllipseData*>::const_iterator it = m_model->m_ellipses.begin();
        for(; it!= m_model->m_ellipses.end(); ++it ){
            drawEllipse( *it );
        }
    }

    
    


/*
    std::list<int*> t;
    int a = 8;

    t.push_back(&a);

    std::list<int*>::iterator it = t.begin();
*/
}

void ModelDraw::blit(wxDC& dc)
{
    dc.Blit(0,0,1024,768, m_memory_dc,0,0 );
}